#pragma once

#include <string>
#include <map>
#include "../engine/singleton.h"

namespace Putin
{

struct Times
{
	Times()
	{
		max = 0.0;
		min = 99999999.0;
		acc = 0.0;
		avg = 0.0;
		cnt = 0;
	}
	double acc;
	double max;
	double min;
	double avg;
	unsigned cnt;
};

/*!
 * Exact timer
 * Does not work good in 
 * multi-core environments
 */
class PerformanceTimer
{
public: 
	void start();
	void end();
	double get();

private:

	__int64 mFreq;
	__int64 mStart;
	__int64 mEnd;
};

typedef std::map<std::string,PerformanceTimer*> ProfMap;
typedef std::map<std::string, Times> ResMap;

class Profiler : public Singleton<Profiler>
{
public:

	std::string getReport();
	void clear();
	void start(std::string function);
	void stop(std::string function);

private:


	ProfMap mFuncs; // Profiling functions
	ResMap	mRes; // results

};

#define startProfile(v) Profiler::instance().start(v)
#define stopProfile(v) Profiler::instance().stop(v)


}